package com.jenings.shop.controller;

import com.jenings.shop.entity.Shopping;
import com.jenings.shop.service.ShoppingServices;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = {"商品sp"})
@RestController
@RequestMapping("/shoppingApi")
public class ShoppingController {
    @Autowired
    ShoppingServices shoppingServices;
    //查询全部商品
    @ApiOperation(value = "查询全部商品")
    @RequestMapping(value = "/selectAll", method = RequestMethod.POST)
    public List<Shopping> selectAll(){
        List<Shopping> shoppingList = shoppingServices.selectAll();
        return shoppingList;
    }
    //查询部分商品,模糊查询
    @ApiOperation(value = "查询部分商品，模糊查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "spname", value = "商品名称", required = true, dataTypeClass = String.class)
    })
    @RequestMapping(value = "/selectSome", method = RequestMethod.POST)
    public List<Shopping> selectSome(String spname){
        List<Shopping> shoppingList = shoppingServices.selectSome(spname);
        return shoppingList;
    }
    //查询指定商品
    @ApiOperation(value = "查询指定商品")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "spname", value = "商品名称", required = true, dataTypeClass = String.class)
    })
    @RequestMapping(value = "/selectByte", method = RequestMethod.POST)
    public Shopping selectByte(String spname){
        Shopping shopping = shoppingServices.selectByte(spname);
        return shopping;
    }
    //修改商品信息
    @ApiOperation(value = "修改商品信息")
    @RequestMapping(value = "/updateByte", method = RequestMethod.POST, produces = "application/json")
    public boolean updateByte(@RequestBody  Shopping shopping){
        return shoppingServices.updateByte(shopping);
    }
    //添加商品
    @ApiOperation(value = "添加商品")
    @RequestMapping(value = "/addByte", method = RequestMethod.POST, produces = "application/json")
    public boolean addByte(@RequestBody  Shopping shopping){
        return shoppingServices.addByte(shopping);
    }
    //删除商品
    @ApiOperation(value = "删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "spid", value = "商品id", required = true, dataTypeClass = String.class)
    })
    @RequestMapping(value = "/delByte", method = RequestMethod.POST)
    public boolean delByte(Integer spid){
        return shoppingServices.delByte(spid);
    }
}
